from time import sleep

from selenium.webdriver.common.by import By
import allure
from util_tools.basePage import BasePage


# 登录页面类
class LoginPage(BasePage):
    url = '/login'
    # 用户名
    username = (By.XPATH, '//*[@id="app"]/div/div/div/form/div[2]/div/div/input')
    # 密码
    password = (By.CSS_SELECTOR, '#app > div > div > div > form > div:nth-child(3) > div > div > input')
    # 登录按钮
    submit = (By.XPATH, '//*[@id="app"]/div/div/div/form/div[4]/div/button')
    # 断言结果
    result_url = 'http://localhost/#/dashboard'

    # 登录操作
    def login(self, user_name, pass_word):
        self.open_url(self.url)
        allure.attach(self.url, '打开登录测试页面', attachment_type=allure.attachment_type.TEXT)
        # 输入用户名
        self.clear_input(self.username)
        self.send_keys(self.username, user_name)
        # 输入密码
        self.clear_input(self.password)
        self.send_keys(self.password, pass_word)
        # 点击登录按钮
        self.click(self.submit)
        sleep(1.5)
        allure.attach(self.screenshots_png(), f'{user_name}:输入内容截屏', attachment_type=allure.attachment_type.PNG)
